package org.budo.launcher.jetty;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

import lombok.Getter;
import lombok.Setter;

/**
 * @author limingwei
 */
@Getter
@Setter
public class BudoIndexHandler extends AbstractHandler {
    private String contextPath;

    public BudoIndexHandler() {}

    public BudoIndexHandler(String contextPath) {
        this.setContextPath(contextPath);
    }

    @Override
    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        PrintWriter writer = response.getWriter();
        writer.println("<a href=\"" + this.getContextPath() + "\">" + this.getContextPath() + "</a>");

        baseRequest.setHandled(true);
    }
}
